<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电梯导航栏</title>
</head>
<style>
    *{
        padding: 0;
        margin: 0;
    }
    a{
        text-decoration: none;
        color: initial;
    }
    .nv{
        background-color: aliceblue;
        display: flex;
        justify-content: center;
        align-items: center;
        border-bottom: 1px solid;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        transition: 0.3s;
    }
    .nc_body{
        display: flex;
        width: fit-content;
    }
    .nc_body a{
        font-size: 20px;
        padding: 10px 20px;
    }
    .test{
        height: 1000vh;
    }
    .noshow{
        transform: translateY(-100%);
    }
</style>
<body>
    <div class="nv noshow">
        <div class="nc_body">
            <a href="">首页</a>
            <a href="">介绍</a>
        </div>
    </div>
    <div class="test"></div>
</body>
<script>
    document.addEventListener("scroll",function(){
        var 滚动位置 = document.documentElement.scrollTop
        var nv = document.querySelector(".nv")
        if(滚动位置 >= 300){
            nv.classList.remove("noshow")
        }else{
            nv.classList.add("noshow")
        }
    })
</script>
</html>